﻿//**************************************************************
//   功能: 将日期类型转换成字符串型格式yyyy-MM-dd  add by lvxz 2008-12-11
//   传入参数 DateIn: 日期类型
//   返回类型：yyyy-mm-dd
//**************************************************************
function ChangeDateToString(DateIn)
    {
    var Year=0;
    var Month=0;
    var Day=0;

    var CurrentDate="";
    //初始化时间
    Year      = DateIn.getYear();
    Month     = DateIn.getMonth()+1;
    Day       = DateIn.getDate();

    CurrentDate = Year + "-";
    if (Month >= 10 )
        CurrentDate = CurrentDate + Month + "-";
    else
        CurrentDate = CurrentDate + "0" + Month + "-";
    if (Day >= 10 )
        CurrentDate = CurrentDate + Day ;
    else
        CurrentDate = CurrentDate + "0" + Day ;
    return CurrentDate;
    }
    
//**************************************************************
//   功能: 将日期类型转换成字符串型格式yyyy年MM月dd  add by lvxz 2008-12-11
//   传入参数 DateIn: 日期类型
//   返回类型：yyyy年mm月dd
//**************************************************************
function ChangeDateFullToString(DateIn)
    {
    var Year=0;
    var Month=0;
    var Day=0;

    var CurrentDate="";
    //初始化时间
    Year      = DateIn.getYear();
    Month     = DateIn.getMonth()+1;
    Day       = DateIn.getDate();

    CurrentDate = Year + "年";
    if (Month >= 10 )
        CurrentDate = CurrentDate + Month + "月";
    else
        CurrentDate = CurrentDate + "0" + Month + "月";
    if (Day >= 10 )
        CurrentDate = CurrentDate + Day +"日";
    else
        CurrentDate = CurrentDate + "0" + Day +"日";
    return CurrentDate;
    }
//**************************************************************
//	功能: 将不标准的日期表达形式转为标准的日期表达形式
//	不标准的日期: 2005-1-3
//	标准化的日期: 2005-01-03
//	bAdjustMonth: 如果bAdjustMonth=true,则转过程中将月份加1以将
//			    月表达换为1-12的形式.
//**************************************************************
function FormatDateString(sDateTime,bAdjustMonth)
	{
    if(!sDateTime)
		return "";
		
	//lijian 更改过，如果日期格式是：2011/05/03；则会出现错误
	sDateTime = sDateTime.ReplaceAll("/", "-").ReplaceAll(".", "-").trim();
	
	var sDatePart, sTimePart;
	if(sDateTime.indexOf(" ")==-1)
	    {
	    sDatePart = sDateTime;
	    sTimePart = "";
	    }
	else
	    {
	    sDatePart = sDateTime.LeftOf(" ");
	    sTimePart = sDateTime.RightOf(" ");
	    }
	
	//日期部分处理
	var aDatePart = sDatePart.split("-");
	var nYear = parseNumEx(aDatePart[0]);
	var nMonth = parseNumEx(aDatePart[1]);
	var nDate = parseNumEx(aDatePart[2]);
	if(bAdjustMonth==true)
	    {
	    nMonth++;
	    if(nMonth==13)
	        {
	        nMonth = 1;
	        nYear++;
	        }
	    }
	sDatePart = nYear + "-" + IntToString(nMonth, 2) + "-" + IntToString(nDate, 2);
	
	//时间部分处理
	if(sTimePart)
	    {
	    var aTimePart = sTimePart.split(":");
	    var nHour  = parseInt(aTimePart[0]);
	    var nMinute = aTimePart.length>1 ? parseInt(aTimePart[1]) : 0;
	    var nSecord = aTimePart.length>2 ? parseInt(aTimePart[2]) : 0;
	    
	    sTimePart = IntToString(nHour, 2) + ":" + IntToString(nMinute, 2) + ":" + IntToString(nSecord, 2);
	    }
	
	if(sTimePart)
	    return sDatePart + " " + sTimePart;
	else
	    return sDatePart;
	}
//*********************************************************************
//	功能: 以字符串的形式返回给定Date对象的年月日
//*********************************************************************
function GetDateString(oDate,bAdjustMonth)
	{
	return FormatDateString(oDate.getYear() + "-" + oDate.getMonth() + "-" + oDate.getDate(),bAdjustMonth)
	}
	
//*********************************************************************
//	功能: 获取指定年的第nWeek周的第一天(星期日)日期
//*********************************************************************
function GetFirstDateOfWeek(nYear,nWeek)
	{		
	//防止传入的不是整数
	if(typeof(nYear)!="number")
		nYear = parseInt(nYear);
		
	if(typeof(nWeek)!="number")
		nWeek = parseInt(nWeek);
	
	var oDate = new Date(nYear,0,1);			//该年第一天
	
	var nDay  = oDate.getDay();	 			//该天的星期	

	oDate.setDate(-nDay+1);					//第一周的第一天
	
	nTotalDate = (nWeek-1)*7;				//从第一周的第一天到本周的日期总数
	
	oDate.setDate(nTotalDate + oDate.getDate()); //本周第一天的日期
	
	return FormatDateString(oDate.getYear() + "-" + oDate.getMonth() + "-" + oDate.getDate(),true);
	}

//*********************************************************************
//	功能: 获取所给日期是当年的第几周
//*********************************************************************
function GetNthWeekOfDate(strDate)
	{
	var nYear = parseInt(strLeft(strDate,"-"));
	
	var strDate1 = "";
	var strDate2 = "";
	for(i=1;i<=53;i++)
		{
		strDate1 = GetFirstDateOfWeek(nYear,i);
		strDate2 = GetFirstDateOfWeek(nYear,i+1);
				
		if((TimeCompare(strDate1,strDate)<=0) && (TimeCompare(strDate2,strDate)>0))
			return i;
		}
	}
//*********************************************************************
// 功能： 日期大小比较 add by lvxz 2008-12-11
// 返回：开始日期大于结束日期 返回false 否则 true
// 参数：日期格式字符串 yyyy-mm-dd
function CompareDate(strbegdate,strenddate)
	{
    var ass,aD,aS;
    var bss,bD,bS;
    var   begin=strbegdate;
    var   over=strenddate;
    ass=begin.split("-");
    aD=new Date(ass[0],ass[1],ass[2]);
    aS=aD.getTime();

    bss=over.split("-");
    bD=new Date(bss[0],bss[1],bss[2]);
    bS=bD.getTime();
    if(aS>bS)
         {
         return false;
         }
     else
          {
          return true;
          }
          
	}

//*********************************************************************
//	功能: 比较oDate1与oDate2的大小,
//	返回: 如果oDate1>oDate2,则返回   1
//	      如果oDate1=oDate2,则返回   0
//	      如果oDate1<oDate2,则返回  -1
//	说明: NotesDateTime的TimeDifference方法比较的两个日期时间不能相隔太多,
//		 否则出错,所以指定本函数
//*********************************************************************
//注意: 短日期可以使用“/”或“-”作为日期分隔符，但是必须用月/日/年的格式来表示，例如"7/20/96"。 

function TimeCompare(sDateTime1,sDateTime2)
	{
	sDateTime1 = Replace(sDateTime1,"/","-");
	sDateTime2 = Replace(sDateTime2,"/","-");
	
	var sDate1 = "";
	var sDate2 = "";
	var sTime1 = "";
	var sTime2 = "";
	
	if(Instr(sDateTime1," "))
		{
		sDate1 = strLeft(sDateTime1," ");
		sTime1 = strRight(sDateTime1," ");
		}
	else
		{
		sDate1 = sDateTime1;
		sTime1 = "00:00:00";
		}
		
	if(Instr(sDateTime2," "))
		{
		sDate2 = strLeft(sDateTime2," ");
		sTime2 = strRight(sDateTime2," ");
		}
	else
		{
		sDate2 = sDateTime2;
		sTime2 = "00:00:00";
		}
		
	//如果日期中没有日,则加上-01
	if(sDate1.indexOf("-")==sDate1.lastIndexOf("-"))
		sDate1 += "-01";
	if(sDate2.indexOf("-")==sDate2.lastIndexOf("-"))
		sDate2 += "-01";	
	
	//转换成: XX月xx日xx年 的形式
	sDate1 = strRight(sDate1,"-") + "-" + strLeft(sDate1,"-");
	sDate2 = strRight(sDate2,"-") + "-" + strLeft(sDate2,"-");
	
	sDateTime1 = sDate1 + " " + sTime1;
	sDateTime2 = sDate2 + " " + sTime2;
	
	if(Date.parse(sDateTime1)>Date.parse(sDateTime2))
		return 1;
	if(Date.parse(sDateTime1)<Date.parse(sDateTime2))
		return -1;
		
	return 0;
	}

//********************************************************************
//	功能: 求时间差(毫秒) (用sDate1减去sDate2)
//	返回: 默认返回毫秒, iReturn可以指定返回类型: 1=秒; 2=分钟; 3=小时;4=天; 默认=毫秒
//********************************************************************
function TimeDifference(sDate1,sDate2, iReturn)
	{
	//除去2007-09-13 22:45:12 ZE8后面的ZE8
	var sTemp = strRightBack(sDate1, ":");
	if(sTemp && sTemp.indexOf(" ")!=-1)
		sDate1 = strLeftBack(sDate1, " ");
		
	var sTemp = strRightBack(sDate2, ":");
	if(sTemp && sTemp.indexOf(" ")!=-1)
		sDate2 = strLeftBack(sDate2, " ");
	
	while(sDate1.indexOf("-")!=-1)
		sDate1 = sDate1.replace("-","/");
		
	while(sDate2.indexOf("-")!=-1)
		sDate2 = sDate2.replace("-","/");
		 
	var oDate1 = new Date(sDate1);
	var oDate2 = new Date(sDate2);
	
	var iValue = (oDate1-oDate2);
	if(iReturn==1)
		iValue /= 1000;
	else if(iReturn==2)
		iValue /= 60000;
	else if(iReturn==3)
		iValue /= 3600000;	
	else if(iReturn==4)
		iValue /= (3600000*24);
	
	return iValue;
	}

//********************************************************************
//	功能: 求时间差(毫秒) (用oTime1减去oTime2)
//	返回: 默认返回毫秒, iReturn可以指定返回类型: 1=秒; 2=分钟; 3=小时;4=天; 默认=毫秒
//********************************************************************
function TimeDifference2(oTime1, oTime2, iReturn)
	{
	var iValue = (oTime1-oTime2);
	if(iReturn==1)
		iValue /= 1000;
	else if(iReturn==2)
		iValue /= 60000;
	else if(iReturn==3)
		iValue /= 3600000;	
	else if(iReturn==4)
		iValue /= (3600000*24);
	
	return iValue;
	}
		
function Now(bGetServerTime)
	{
	if(bGetServerTime)
	    {
	    return GetServerNowTime();
	    }
	else
	    {
	    var oNowTime = new Date();
	    return GetDateString(oNowTime,true) + " " + oNowTime.getHours() + ":" + oNowTime.getMinutes() + ":" + oNowTime.getSeconds();
	    }
	}
	

function ToDate(bGetServerTime)
	{
	if(bGetServerTime)
	    {
	    return GetServerNowTime().LeftOf(" ");
	    }
	else
	    {
	    var oNowTime = new Date();
	    return GetDateString(oNowTime,true);
	    }
	}


function ToMonth(bGetServerTime)
	{
	if(bGetServerTime)
	    {
	    return ToDate(true).LeftOfLast("-");
	    }
	else
	    {
	    return ToDate(false).LeftOfLast("-");
	    }
	}
	
function ToYear(bGetServerTime)
	{
	if(bGetServerTime)
	    {
	    return ToDate(true).LeftOf("-");
	    }
	else
	    {
	    return ToDate(false).LeftOf("-");
	    }
	}
	
//功能：判断所给的字符串是不是合格的日期格式
function IsValidDate(sDate)
	{
	sDate = Replace(sDate,"/","-");
	var aTemp = sDate.split("-");
	sDate = aTemp[2] + "-" + aTemp[0] + "-" + aTemp[1];
	if(isNaN(Date.parse(sDate)))
		return false;
	else
		return true;
	}

//**************************************************************
//	功能: 格式化时间长度(考虑工作日)
//	参数: iTimeLength=时间长度(分钟数)
//		 b24Hour = 一天是否要以24小时来计算, 否的话以工作日进行计算
//**************************************************************
function FormatTimeLengthStr(iTimeLength, b24Hour)
	{
	var iWorkDayLength = 8;
	if(b24Hour)
	    {
	    iWorkDayLength = 24;
	    }
	    
	var sReturn = "";
	if(iTimeLength<0)
	    {
	    sReturn += "-";
	    iTimeLength = 0 - iTimeLength;
	    }
	    
	var iDays = 0;
	var iHours = 0;
	var iMinutes = 0;
	var iSeconds = 0;
	
	//计算秒
	iSeconds = iTimeLength % 60;
	iTimeLength = iTimeLength - iSeconds;
	
	//分钟
	if(iTimeLength>0)
	    {
	    iTimeLength = iTimeLength / 60;
	    iMinutes = iTimeLength % 60;
	    iTimeLength = iTimeLength - iMinutes;
	    }
	
	//小时
	if(iTimeLength>0)
	    {
	    iTimeLength = iTimeLength / 60;
	    iHours = iTimeLength % iWorkDayLength;
	    iTimeLength = iTimeLength - iHours;
	    }
	    
	//天
	if(iTimeLength>0)
	    {
	    iDays = iTimeLength / iWorkDayLength;
	    }
	    
	if(iDays>0)
	    {
	    sReturn += iDays + "天";
	    }
	 
	if(iHours>0)
	    {
	    sReturn += iHours + "小时";
	    }
	    
    if(iMinutes>0)
	    {
	    sReturn += iMinutes + "分";
	    }
	    
	if(iSeconds>0)
	    {
	    sReturn += iSeconds + "秒";
	    }   
	    
	return sReturn;    
	}

//**************************************************************
//	功能: 计算时限(考虑各种节假日, 工作日的情况)
//	参数: sStartTime=开始时间, iTimeLength=办理时间长度(小时)
//**************************************************************
function CalculateTimeLimit(sStartTime, iTimeLength)
	{
	if(!sStartTime)
		sStartTime = "";
	return GetServerData("DateTime_CalculateTimeLimit", "StartTime=" + sStartTime + "&Length=" + iTimeLength);
	}

//功能: 从服务器获取当前时间
function GetServerNowTime()
	{
	return ExecServerFunction("MyDateTime.GetNowTime");
	}

//调整时间: 增加日数
function AdjustDate(sDateTime, iAdjustCount) //
	{
	sDateTime = Replace(sDateTime,"/","-");	
	var sDate = "", sTime = "";
	var bWithTime;
	
	if(!iAdjustCount)
		iAdjustCount = 1;
	
	if(Instr(sDateTime," "))
		{
		sDate = strLeft(sDateTime," ");
		sTime = strRight(sDateTime," ");
		bWithTime = true;
		}
	else
		{
		sDate = sDateTime;
		sTime = "00:00:00";
		bWithTime = false;
		}

	//如果日期中没有日,则加上-0
	if(sDate.indexOf("-")==sDate.lastIndexOf("-"))
		sDate += "-0";
	
	//转换成: XX月xx日xx年 的形式
	sDate = strRight(sDate,"-") + "-" + strLeft(sDate,"-");
	var oDate = new Date(Date.parse(sDate + " " + sTime) + iAdjustCount*86400000);
	var sReturn  = oDate.getYear() + "-" + (oDate.getMonth()+1) + "-" + oDate.getDate();
	if(bWithTime)
		sReturn += " " + oDate.getHours() + ":" + oDate.getMinutes() + ":" + oDate.getSeconds();
		
	return FormatDateString(sReturn);
	}
	
//////////////////////////////////////////////////////////////////////////
//  功能: 增加年(iYear是Double类型的数字,可以是负数)
//////////////////////////////////////////////////////////////////////////
function AddYears(sBeginTime, iYear)
    {
    var sUrl = _MyWebsite.CommonElementsFolderUrl() + "/Agents/DateTime/AddYear.aspx";
    var sParam = "DateTime=" + sBeginTime + "&Count=" + iYear;
    return GetServerData(sUrl, sParam);
    }

//////////////////////////////////////////////////////////////////////////
//  功能: 增加月(iMonth是Double类型的数字,可以是负数)
//////////////////////////////////////////////////////////////////////////
function AddMonths(sBeginTime, iMonth)
    {
    var sUrl = _MyWebsite.CommonElementsFolderUrl() + "/Agents/DateTime/AddMonth.aspx";
    var sParam = "DateTime=" + sBeginTime + "&Count=" + iMonth;
    return FormatDateString(GetServerData(sUrl, sParam));
    }
 
//////////////////////////////////////////////////////////////////////////
//  功能: 增加日(iDay是Double类型的数字,可以是负数)
//////////////////////////////////////////////////////////////////////////
function AddDays(sBeginTime, iDay)
    {
    var sUrl = _MyWebsite.CommonElementsFolderUrl() + "/Agents/DateTime/AddDay.aspx";
    var sParam = "DateTime=" + sBeginTime + "&Count=" + iDay;
    var sDate = GetServerData(sUrl, sParam);
    return FormatDateString(sDate);
    }   
    
//////////////////////////////////////////////////////////////////////////
//  功能: 增加小时(iHour是Double类型的数字,可以是负数)
//////////////////////////////////////////////////////////////////////////
function AddHours(sBeginTime, iHour)
    {
    var sUrl = _MyWebsite.CommonElementsFolderUrl() + "/Agents/DateTime/AddHour.aspx";
    var sParam = "DateTime=" + sBeginTime + "&Count=" + iHour;
    var sDate = GetServerData(sUrl, sParam);
    return FormatDateString(sDate);
    }
    
//////////////////////////////////////////////////////////////////////////
//  功能: 增加分钟(iMinute是Double类型的数字,可以是负数)
//////////////////////////////////////////////////////////////////////////
function AddMinutes(sBeginTime, iMinute)
    {
    var sUrl = _MyWebsite.CommonElementsFolderUrl() + "/Agents/DateTime/AddMinute.aspx";
    var sParam = "DateTime=" + sBeginTime + "&Count=" + iMinute;
    var sTime = GetServerData(sUrl, sParam);
    return FormatDateString(sTime);
    }
    
//////////////////////////////////////////////////////////////////////////
//  功能: 增加秒(iSecond是Double类型的数字,可以是负数)
//////////////////////////////////////////////////////////////////////////
function AddSeconds(sBeginTime, iSecond)
    {
    var sUrl = _MyWebsite.CommonElementsFolderUrl() + "/Agents/DateTime/AddSecond.aspx";
    var sParam = "DateTime=" + sBeginTime + "&Count=" + iSecond;
    return FormatDateString(GetServerData(sUrl, sParam));
    }
    
//功能: 将字符串所表示的时间转换成Date对象
function ParseDateTime(sDateTime)
	{
	sDateTime = Replace(sDateTime,"/","-");	
	var sDate = "", sTime = "";
	
	if(Instr(sDateTime," "))
		{
		sDate = strLeft(sDateTime," ");
		sTime = strRight(sDateTime," ");
		}
	else
		{
		sDate = sDateTime;
		sTime = "00:00:00";
		}

	//如果日期中没有日,则加上-0
	if(sDate.indexOf("-")==sDate.lastIndexOf("-"))
		sDate += "-0";
	
	//转换成: XX月xx日xx年 的形式
	sDate = strRight(sDate,"-") + "-" + strLeft(sDate,"-");
	return new Date(Date.parse(sDate + " " + sTime));
	}

//************************************************************************************************************
//   功能: 将日期类型转换成中文描述格式, 如: 2009-05-09 09:30:05 转成 2009年5月9日 9时30分5秒
//************************************************************************************************************
function FormatDateString_CH(sDateTime)
	{
	sDateTime = sDateTime.trim();
	if(!sDateTime)
		return "";
		
	sDateTime = Replace(sDateTime, "/", "-");
	var sDatePart = sDateTime;
	var sTimePart = "";
	if(sDatePart.indexOf(" ")!=-1)
		{
	    sDatePart = strLeft(sDateTime, " ");
		sTimePart = strRight(sDateTime, " ");
	    }
	
	var aDatePart = sDatePart.split("-");
	
	if(aDatePart[1] && aDatePart[1].substr(0,1)=="0")
		aDatePart[1] = aDatePart[1].substr(1,1);
	
	if(aDatePart[2] && aDatePart[2].substr(0,1)=="0")
		aDatePart[2] = aDatePart[2].substr(1,1);
	
	sDateTime = aDatePart[0] + "年";
	if(aDatePart[1])
	    sDateTime += aDatePart[1] + "月";
	    
	if(aDatePart[2])
	    sDateTime += aDatePart[2] + "日";
	
	if(sTimePart!="")
		{
		sDateTime += " "
	    var aTimePart = sTimePart.split(":");
    	
	    if(aTimePart.length>0)
		    {
		    if(aTimePart[0].substr(0,1)=="0")
			    aTimePart[0] = aTimePart[0].substr(1,1);
		    sDateTime += aTimePart[0] + "时";
		    }
    			
	    if(aTimePart.length>1)
		    {
		    if(aTimePart[1].substr(0,1)=="0")
			    aTimePart[1] = aTimePart[1].substr(1,1);
		    sDateTime += aTimePart[1] + "分";
		    }

		if(aTimePart.length>2)
			{
			if(aTimePart[2].substr(0,1)=="0")
				aTimePart[2] = aTimePart[2].substr(1,1);
			sDateTime += aTimePart[2] + "秒";
			}
		}
	return sDateTime;
	}

//功能：举例说明，将2011-11-19转换为 二O一一 年 九 月 十九 日 
function FormatDateString_CH2(sDateTime)
    {
    //2011-11-29转换为二0一一年一一月二九日
    sDateTime = FormatDateString_CH(sDateTime);
    sDateTime = sDateTime.ReplaceAll("1","一");
    sDateTime = sDateTime.ReplaceAll("2","二");
    sDateTime = sDateTime.ReplaceAll("3","三");
    sDateTime = sDateTime.ReplaceAll("4","四");
    sDateTime = sDateTime.ReplaceAll("5","五");
    sDateTime = sDateTime.ReplaceAll("6","六");
    sDateTime = sDateTime.ReplaceAll("7","七");
    sDateTime = sDateTime.ReplaceAll("8","八");
    sDateTime = sDateTime.ReplaceAll("9","九");
    //一一改为十一，二九改为二十九
    var sYear = sDateTime.LeftOf("年");
    var sMonth = sDateTime.LeftOf("月").RightOf("年");
    var sDate = sDateTime.RightOf("月").LeftOf("日");
    if(sMonth.length > 1)
        {
        sMonth = "十" + sMonth.RightOf("一");
        }
    if(sDate.length > 1)
        {
        if(sDate.charAt(0) == "一")
            {
            sDate = "十" + sDate.charAt(1);
            }
        else 
            {
            sDate = sDate.charAt(0) + "十" + sDate.charAt(1);
            }
        }
    sDateTime = sYear + " 年 " + sMonth + " 月 " + sDate + " 日 ";
    return sDateTime;
    }
    
//功能：获取一个月除了周六周日之外的所有日期   
function GetWorkDatesOfMonth(iYear, iMonth)
    {
    return ExecServerFunction("MyDateTime.GetWorkDatesOfMonth", null, iYear, iMonth);
    }
    

//功能: 获取指定日期的星期    
function GetWeekDayCH(sDate)
    {
    sDate = sDate.ReplaceAll("/", "-");
    sDate = sDate.ReplaceAll("年", "-");
    sDate = sDate.ReplaceAll("月", "-");
    sDate = sDate.ReplaceAll("日", "-");
    var aDateParts = sDate.split("-");
    var iYear = parseNumEx(aDateParts[0]);
    var iMonth = parseNumEx(aDateParts[1]);
    var iDay  = parseNumEx(aDateParts[2]);
    var oDate = new Date(iYear, iMonth-1, iDay);
    var iWeekDay = oDate.getDay();
    switch(iWeekDay)
        {
        case 0:
            return "星期日";
            break;
            
        case 1:
            return "星期一";
            break;  
              
        case 2:
            return "星期二";
            break; 
               
        case 3:
            return "星期三";
            break;  
              
        case 4:
            return "星期四";
            break;  
              
        case 5:
            return "星期五";
            break; 
               
        case 6:
            return "星期六";
            break;
        }
    }
 
//获取某个月的最后一天的数字（28、29、30或者31） 
function GetLastDateNumberOfMonth(iYear, iMonth)
    {
    iMonth = iMonth-1;
    for(var i=28; i<=32; i++)
        {
        var oDate = new Date(iYear, iMonth, i);
        if(oDate.getMonth()!=iMonth)
            {
            return i-1;
            }
        }
    }

/********************************************************************************************
 * 格式化日期,
 * 例如：20130410140012表示2013年4月10日14时0分12秒，对应的format为：yyyyMMddhhmmss
 * M:Month,d:day,h:hour,m:minute,s:second,q:季度,S:millisecond
 * 使用示例: var oDate =  new Date(); var sDateString = oDate.format('yyyyMMddhhmmss');
********************************************************************************************/
Date.prototype.format= function (format)    
    {        
    var o = {        
    "M+" : this.getMonth()+1, //month        
    "d+" : this.getDate(),    //day        
    "h+" : this.getHours(),   //hour        
    "m+" : this.getMinutes(), //minute        
    "s+" : this.getSeconds(), //second        
    "q+" : Math.floor((this.getMonth()+3)/3),  //quarter        
    "S" : this.getMilliseconds() //millisecond        
    }        
    if(/(y+)/.test(format))format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));        
    for(var k in o)
        {
        if(new RegExp("("+ k +")").test(format))
            {
            format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k]:("00"+ o[k]).substr((""+ o[k]).length)); 
            }        
        }
             
    return format;    
    }